#!/usr/bin/env python
#coding=utf8

# 判断实际值和期望值

import re
import logging
import types

def evalString(actual, operator,expect):
    OPERATORS = ['=', '!=', 'contains', '!contains', 'match']

    # 校验运算符
    if operator.strip() == '':
        logging.debug('operator参数不能为空')
    elif (operator not in OPERATORS):
        logging.debug('不支持【' + operator + '】运算符')

    elif operator.strip() == '=':
        return expect == actual
    elif operator.strip() == '!=':
        return expect != actual
    elif operator.strip() == 'contains':
        return expect in actual
    elif operator.strip() == '!contains':
        return expect not in actual
    elif operator.strip() == 'match':
        if (re.match(expect, actual) == None):
            return False
        else:
            return True
    else:
        return False

#获取字典中的objkey对应的值，适用于字典嵌套
#dict:字典
#objkey:目标key
#default:找不到时返回的默认值

def getFieldValue(tmp, objkey, default):

    print objkey
    for k,v in tmp.items():
        if k== objkey:
            return v
        else:
            if type(v) is types.DictType:
                ret = getFieldValue(v, objkey, default)
                if ret is not default:
                    return ret
    return default

def getJsonKeyValue(data, parm):
	str = ''
	print  len(parm)
	print parm
	if(len(parm)==1):
		print  data[parm[0]]
		str =  data[parm[0]]
	else:
		for n in parm:
			data = data[n]
			print data
			str =  data
	return str


